package com.gzsxy.event;


import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;



/**
 * @author xiaolong
 * @version 1.0
 * @description: 处理登录成功的事件
 * @date 2021/11/8 17:30
 */
@Component
public class AuthenticationSuccessEventListener implements ApplicationListener<AuthenticationSuccessEvent> {



    @Override
    public void onApplicationEvent(AuthenticationSuccessEvent authenticationSuccessEvent) {
        //获取当前用户信息
        UserDetails userDetails = (UserDetails) authenticationSuccessEvent.getAuthentication().getPrincipal();
        String username = userDetails.getUsername();

        System.out.println("登录成功的事件 当前用户名:"+username);
    }
}
